package com.example.tech34Base64;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class sqlmanage {
    private Connection con = null;//数据库连接，从DriverManager的方法获得，用以产生执行sql的PreparedStatement

    public sqlmanage() throws SQLException, ClassNotFoundException {
        //step1 加载数据库驱动
//        Class.forName("com.mysql.jdbc.Driver");
        Class.forName("com.mysql.cj.jdbc.Driver");
        System.out.println("数据库驱动加载成功");
        //step2 连接数据库
        this.con = DriverManager.getConnection("jdbc:mysql://123.56.10.239:3306/cover_cloud?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8",
                "cover", "Cover2022,.");
        System.out.println("数据库连接成功");
    }

    public void close() throws SQLException {
        this.con.close();
    }

    public void select() throws SQLException {
        //创建sql语句
        String sql = "insert into student(name,age,high)value(?,?,?)";
        //PreparedStatement能够对SQL语句进行预编译，这样防止了   SQL注入 提高了安全性。
        PreparedStatement ps = con.prepareStatement(sql);
        //执行 sql 因为这里插入操作就不对结处理
        ps.executeUpdate();
        ps.close();
    }

    public static void main(String[] args) throws SQLException, ClassNotFoundException {
        sqlmanage sqlmanage = new sqlmanage();
        System.out.println(111);
    }

}
